package cn.iocoder.yudao.module.shop.admin.api;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.api.shop.admin.ShopUserApi;
import cn.iocoder.yudao.module.api.shop.admin.dto.ShopAdminRespDTO;
import cn.iocoder.yudao.module.shop.admin.pojo.po.ShopUser;
import cn.iocoder.yudao.module.shop.admin.service.ShopUserService;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2024/12/10
 */
@Service
@Validated
public class ShopUserApiImpl implements ShopUserApi {
    @Resource
    private ShopUserService shopUserService;

    @Nonnull
    @Override
    public Set<Long> getShopIdsByUserId(Long userId, Integer userType) {
        return shopUserService.getShopIdsByUserId(userId, userType);
    }

    @Nonnull
    @Override
    public List<ShopAdminRespDTO> getShopAdminListByShopId(Long shopId) {
        List<ShopUser> list = shopUserService.getAdminListByShopId(shopId);
        if (CollUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        return BeanUtils.toBean(list, ShopAdminRespDTO.class);
    }

    @Override
    public ShopAdminRespDTO getAdmin(Long shopId, Long userId, Integer userType) {
        ShopUser adminDO = shopUserService.getAdmin(shopId, userId, userType);
        return BeanUtils.toBean(adminDO, ShopAdminRespDTO.class);
    }

}
